﻿using UnityEngine;
using System.Collections;

public class AttackObjectBehavior : MonoBehaviour {
	
	public PlayerStats attacker;
	public PlayerStats defender;
	
	public bool doAttack;
	
	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		if (attacker != null && defender != null)
		{
			if(doAttack)
			{
				if (Random.Range(0, 100) < attacker.HitPercentage(defender.shipType) - defender.EvadePercentage()) //Hit
				{
					int damage = attacker.CalculateDamage();
					damage = defender.DamageDone(damage);
					
					if (Random.Range(0, 100) > defender.Luck) //Critical Dodge
					{	
						defender.DealDamage(damage, attacker.weaponType);
					}
				}
				
				attacker = null;
				defender = null;
			}
		}
	}
}
